<?php

namespace app\admin\controller;


class Comment extends Base
{
    //评论列表
    public function all()
    {
        //查询出评论列表按时间倒序排序
        $comments = model('Comment')->order('create_time', 'asc')->paginate(20);
        //定义模板变量
        $viewData = [
            'comments' => $comments
        ];
        //渲染
        $this->assign($viewData);
        return view();
    }

    //评论删除
    public function del()
    {
        //从数据库里查询出评论id，先查询后删除
        $commentInfo = model('Comment')->find(input('post.id'));
        $result = $commentInfo->delete();
        if ($result){
            //删除成功
            $this->success('删除成功','admin/comment/all');
        }else{
            $this->error('删除失败');
        }
    }
}
